﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using W7Toshil.Entity;
using System.Collections.Generic;

namespace W7Toshil.Services
{
    public class TagNameTransactionViewBuilder : ITransactionViewBuilder 
    {
        Dictionary<string, List<Expense>> expenseDict = new Dictionary<string, List<Expense>>();
        public void Add(Expense expense)
        {
            if (expenseDict.ContainsKey(expense.TagName))
            {
                List<Expense> expenses = expenseDict[expense.TagName];
                expenses.Add(expense);
            }
            else
            {
                List<Expense> expenses = new List<Expense>();
                expenses.Add(expense);

                expenseDict.Add(expense.TagName, expenses);
            }
        }

        public IList<TransactionView> FetchAll()
        {
            IList<TransactionView> transactionViewList = new List<TransactionView>();
            foreach (string key in expenseDict.Keys)
            {
                List<Expense> expenses = expenseDict[key];
                TransactionView view = new TransactionView()
                {
                    Header = key,
                    TransactionDetail = expenses
                };

                transactionViewList.Add(view);

            }

            return transactionViewList;
        }

    }
}
